#include	"LogApp.h"
#include	"LogService.h"
#include	<IniFile.h>

bool LogApp::OnInit(Command & cmd) {
	IniFile conf;
	if (!conf.Load("./config.ini")) throw std::runtime_error("Missing config.ini");

	int log_level = conf.Get<int>("logserver", "log_level", ELog::Info);
	Logger::Instance().Init("logserver", "logs", 4194304, (ELog::Level)log_level);

	std::string listen_ip = conf.Get<std::string>("logserver", "ip", "127.0.0.1");
	int listen_port = conf.Get<int>("logserver", "port", 10002);
	if (LogService::Instance().Listen(listen_ip, listen_port) != ENet::Success) {
		LOG_ERR("Failed to listen on %s:%d", listen_ip.c_str(), listen_port);
		return false;
	}

	LOG_INFO("Application logserver started ...");
	return true;
}

void LogApp::OnExit(int code) {
	LOG_INFO("Application logserver will exit : %d", code);
}

RUN_APP(LogApp)